<?php

namespace App\Http\Controllers\Admins;

use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Jenson\Core\Libraries\Helper as CoreHelper;

class BaseAdminController extends Controller
{
    public $admin_id;
    public $admin;
    public $username;
    /**
     * BaseAdminController constructor.
     * @param Request $request
     */
    public function __construct(Request $request)
    {
//        $this->middleware('auth:api', ['except' => ['login']]);
        parent::__construct($request);
        CoreHelper::LoadConfig();
    }

    /**
     * @return RedirectResponse
     *
     * 成功返回
     */
    public function retSuccess(): RedirectResponse
    {
        return redirect()->back()->withErrors("success")->withInput();
    }

    /**
     * @param $msg
     * @param $request
     * @return RedirectResponse
     *
     * 错误返回
     */
    public function retError($msg,$request): RedirectResponse
    {
        return redirect()->back()->withErrors($msg)->withInput($request->all());
    }

    /**
     * @param $exception
     * @return RedirectResponse
     *
     * 异常返回
     */
    public function retException($exception): RedirectResponse
    {
        return redirect()->back()->withErrors($exception->getMessage())->withInput();
    }

    /**
     * 返回信息
     *
     * @param int $code
     * @param $msg
     * @param $data
     * @return array
     */
    protected function returnInfo(int $code = 1 , $msg = null , $data = null): array
    {
        return [
            'code'=>$code,
            'msg'=>$msg,
            'data'=>$data
        ];
    }
}
